package com.example.activitysign.controller;

import com.example.activitysign.pages.AjaxResult;
import com.example.activitysign.pages.PageResult;
import com.example.activitysign.pages.PageValidate;
import com.example.activitysign.service.IActivityAwardService;
import com.example.activitysign.validate.ActivityAwardCreateValidate;
import com.example.activitysign.validate.ActivityAwardSearchValidate;
import com.example.activitysign.validate.ActivityAwardUpdateValidate;
import com.example.activitysign.vo.activity.ActivityAwardDetailVo;
import com.example.activitysign.vo.activity.ActivityAwardListedVo;
import com.example.activitysign.vo.activity.ActivityUserAwardVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 奖品管理
 */
@Slf4j
@RestController
@RequestMapping("api/activityAward")
public class ActivityAwardController {

    @Resource
    private IActivityAwardService iActivityAwardService;

    @PostMapping("/list")
    public AjaxResult<PageResult<ActivityAwardListedVo>> list(@Validated PageValidate pageValidate,
                                                              @Validated @RequestBody ActivityAwardSearchValidate searchValidate) {
        pageValidate.setPageSize(searchValidate.getPageSize());
        pageValidate.setPageNo(searchValidate.getPageNo());
        searchValidate.setEquityName(searchValidate.getAward());
        PageResult<ActivityAwardListedVo> list = iActivityAwardService.list(pageValidate, searchValidate);
        return AjaxResult.success(list);
    }

    @GetMapping("/detail")
    public AjaxResult<ActivityAwardDetailVo> detail(@Validated @RequestParam("id") Long id) {
        ActivityAwardDetailVo detail = iActivityAwardService.detail(id);
        return AjaxResult.success(detail);
    }


    @PostMapping("/add")
    public AjaxResult<Object> add(@Validated @RequestBody ActivityAwardCreateValidate createValidate) {
        iActivityAwardService.add(createValidate);
        return AjaxResult.success();
    }

    /**
     * 奖品编辑
     *
     * @param updateValidate
     * @return
     */
    @PostMapping("/edit")
    public AjaxResult<Object> edit(@Validated @RequestBody ActivityAwardUpdateValidate updateValidate) {
        iActivityAwardService.edit(updateValidate);
        return AjaxResult.success();
    }


    @GetMapping("/userGetList")
    public AjaxResult<PageResult<ActivityUserAwardVo>> userGetList(@Validated PageValidate pageValidate,
                                                                   @Validated @RequestBody ActivityAwardSearchValidate searchValidate) {
        PageResult<ActivityUserAwardVo> list = iActivityAwardService.userGetList(pageValidate, searchValidate);
        return AjaxResult.success(list);
    }

}
